package org.agile.grenoble.userresources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.agile.grenoble.data.AnswersStorage;
import org.agile.grenoble.data.IUserStorage;
import org.agile.grenoble.data.StorageException;
import org.agile.grenoble.user.User;
import org.agile.grenoble.user.UserFactory;

@Path("/addUser")
public class AddUserResource {

  // The Java method will process HTTP POST requests
  @GET
  // The Java method will produce content identified by the MIME Media
  @Produces("text/plain")
  public String getClichedMessage(@QueryParam("username") String username,
    @QueryParam("email") String email) {
    //public String getClichedMessage() {
    IUserStorage storage = new AnswersStorage();
    String answers = "ERROR with Mysql";
    try {
      storage.initializeUserDb();
      User user = UserFactory.getUser(username, email, storage);
      answers = "" + user.getId();
    } catch (StorageException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return answers;
  }
}